It is often desirable to snap items to a grid or to guidelines, so that users can easily line them up accurately.

In WPF Diagrams, snapping is controlled using the DiagramSurface.HorizontalSnapSpecifier and DiagramSurface.VerticalSnapSpecifier properties.

To snap items to a regular grid, set these properties to a SnapToIntervalSnapSpecifier. You can do this by creating an instance of SnapToIntervalSnapSpecifier as a resource:
CopySnapping to a regular grid
<Window.Resources>
  <ms:SnapToIntervalSnapSpecifier x:Key="Every20Units" Interval="20" />
</Window.Resources>

<ms:DiagramSurface HorizontalSnapSpecifier="{StaticResource Every20Units}" />

or by using the SnapToInterval markup extension:

CopySnapping to a regular grid
<ms:DiagramSurface HorizontalSnapSpecifier="{ms:SnapToInterval 20}" />
To create your own snapping algorithm, for example to use a non-regular grid (e.g. snap to guidelines or snap to other objects), implement ISnapSpecifier.

For information about drawing snap lines, see Drawing the Diagram Background.